package com.deimos.dataBase;

import java.io.File;
import java.util.Date;

import org.vast.util.DateTime;

public class Cloud {
	public static String FILE = (new File(Cloud.class.getResource("Cloud.class").toString()).getParent() + "/../../../../clouds.txt").replace("file:", "");
	
	private double percentage;
	private double point1lat;
	private double point1long;
	private double point2lat;
	private double point2long;
	private double point3lat;
	private double point3long;
	private double point4lat;
	private double point4long;
	private double size = 4;
	
	private Integer day;
	private long start;
	private long stop;
	private long knownAbout;
	private Integer cloudId;
	private PolygonD polygon = new PolygonD();

	
	public void addPoint(Double x, Double y){
		polygon.addPoint(x, y);
	}
	
	public boolean contains(Double x, Double y){
		return polygon.isInside(x, y);
	}

	public long getKnownAbout() {
		return knownAbout;
	}

	public void setKnownAbout(long knowAbout) {
		this.knownAbout = knowAbout;
	}

	public long getStart() {
		return start;
	}

	public void setStart(long start) {
		this.start = start;
	}

	public long getStop() {
		return stop;
	}

	public void setStop(long stop) {
		this.stop = stop;
	}

	public double getPercentage() {
		return percentage;
	}

	public void setPercentage(double percentage) {
		this.percentage = percentage;
	}

	public Integer getCloudId() {
		return cloudId;
	}

	public void setCloudId(Integer cloudId) {
		this.cloudId = cloudId;
	}

	public Integer getDay() {
		return day;
	}

	public void setDay(Integer day) {
		this.day = day;
	}

	public double getSize() {
		return size;
	}

	public void setSize(double size) {
		this.size = size;
	}

	public double getPoint1lat() {
		return point1lat;
	}

	public void setPoint1lat(double point1lat) {
		this.point1lat = point1lat;
	}

	public double getPoint1long() {
		return point1long;
	}

	public void setPoint1long(double point1long) {
		this.point1long = point1long;
	}

	public double getPoint2lat() {
		return point2lat;
	}

	public void setPoint2lat(double point2lat) {
		this.point2lat = point2lat;
	}

	public double getPoint2long() {
		return point2long;
	}

	public void setPoint2long(double point2long) {
		this.point2long = point2long;
	}

	public double getPoint3lat() {
		return point3lat;
	}

	public void setPoint3lat(double point3lat) {
		this.point3lat = point3lat;
	}

	public double getPoint3long() {
		return point3long;
	}

	public void setPoint3long(double point3long) {
		this.point3long = point3long;
	}

	public double getPoint4lat() {
		return point4lat;
	}

	public void setPoint4lat(double point4lat) {
		this.point4lat = point4lat;
	}

	public double getPoint4long() {
		return point4long;
	}

	public void setPoint4long(double point4long) {
		this.point4long = point4long;
	}

	public String toString() {
		String cloud = "";
		cloud = cloud + "<Cloud>\n";
		cloud = cloud + "\t<CloudId>" + this.cloudId + "</CouldId>\n";
		cloud = cloud + "\t<Day>" + this.day + "</Day>\n";
		cloud = cloud + "\t<Percentage>" + this.percentage + "</Percentage>\n";

		cloud = cloud + "\t<Region>\n";

		cloud = cloud + "\t\t<Point>\n";
		cloud = cloud + "\t\t\t<Long>" + this.point1long + "</Long>\n";
		cloud = cloud + "\t\t\t<Lat>" + this.point1lat + "</Lat>\n";
		cloud = cloud + "\t\t</Point>\n";

		cloud = cloud + "\t\t<Point>\n";
		cloud = cloud + "\t\t\t<Long>" + this.point2long + "</Long>\n";
		cloud = cloud + "\t\t\t<Lat>" + this.point2lat + "</Lat>\n";
		cloud = cloud + "\t\t</Point>\n";

		cloud = cloud + "\t\t<Point>\n";
		cloud = cloud + "\t\t\t<Long>" + this.point3long + "</Long>\n";
		cloud = cloud + "\t\t\t<Lat>" + this.point3lat + "</Lat>\n";
		cloud = cloud + "\t\t</Point>\n";

		cloud = cloud + "\t\t<Point>\n";
		cloud = cloud + "\t\t\t<Long>" + this.point4long + "</Long>\n";
		cloud = cloud + "\t\t\t<Lat>" + this.point4lat + "</Lat>\n";
		cloud = cloud + "\t\t</Point>\n";

		cloud = cloud + "\t</Region>\n";
		cloud = cloud + "</Cloud>\n";
		return cloud;
	}

	
	public String toString(String token){
		String text = "";
		text = text + token + "<Cloud>" + "\n";
		text = text +token + "\t<CloudId>" + this.cloudId + "</CloudId>\n";
		text = text +token + "\t<Start>" + this.start + "</Start>\n";
		text = text +token + "\t<Stop>" + this.stop + "</Stop>\n";
		text = text +token + "\t<KnownAbout>" + this.knownAbout + "</KnownAbout>\n";
		text = text + token + "\t<Region>\n";
		for (int i = 0 ; i < this.polygon.npoints; i ++){
			
			text = text + token + "\t\t<Point>\n";
			text = text +token + "\t\t\t<Long>" + this.polygon.xpoints[i] + "</Long>\n";
			text = text +token + "\t\t\t<Lat>" + this.polygon.ypoints[i] + "</Lat>\n";
			text = text + token + "\t\t</Point>\n";
		}
		text = text + token + "\t</Region>\n";
		text = text +token + "</Unavailabiltiy>";
		return text;
	}
	
	public DateTime getStartTime(Date initDate){
		return new DateTime(initDate.getTime() + secondsToMiliseconds(this.start)); 
	}
	
	public DateTime getStopTime(Date initDate){
		return new DateTime(initDate.getTime() + secondsToMiliseconds(this.stop)); 
	}
	
	public DateTime getKnownTime(Date initDate){
		return new DateTime(initDate.getTime() + secondsToMiliseconds(this.knownAbout)); 
	}
	
	public long secondsToMiliseconds(long seconds){
		return seconds * 1000;
	}

}


